/**
* 头部菜单
*/ 
<template>
  <el-menu
    class="el-menu-demo"
    mode="horizontal"
    text-color="#ccc"
    active-text-color="#f00"
  >
    <!-- <p class="notice" @click="linkOrder">
      <i class="iconfont">&#xe6b7;</i>
      <i class="hearts" style="display:none"></i>
    </p> -->
    <div id="head">
      <div class="nactione">
        <el-badge :value="12" class="item">
          <i class="iconfont">&#xe6b7;</i>
        </el-badge>
      </div>
      <img src="../assets/img/head.png" alt="" class="headImg" />
      <el-submenu index="2" class="submenu" collapse-transition="true">
        <template slot="title" class="nameUser">张三</template>
        <div id="set">
          <el-menu-item index="2-1" class="centers">
            <i class="el-icon-setting"></i>设置
          </el-menu-item>
          <el-menu-item @click="content()" index="2-2" class="centers">
            <i class="el-icon-user"></i>个人中心
          </el-menu-item>
          <el-menu-item @click="exit()" index="2-3" class="centers">
            <i class="el-icon-right"></i>退出
          </el-menu-item>
        </div>
      </el-submenu>
    </div>
  </el-menu>
</template>
<script>
import { loginout } from "../api/userMG";
import { mapState, mapMutations } from "../vuex/store";
export default {
  name: "navcon",
  data() {
    return {
      collapsed: true,
      imgshow: require("../assets/img/show.png"),
      imgsq: require("../assets/img/sq.png"),
      user: {},
      notify: {}, //消息通知
    };
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.user = JSON.parse(localStorage.getItem("userdata"));
  },
  methods: {
    // 退出登录
    exit() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 关闭浏览器窗口的时候清空浏览器缓存在localStorage的数据
          var storage = window.localStorage;
          storage.clear();
          setTimeout(() => {
            this.$store.commit("logout", "false");
            this.$router.push({ path: "/login" });
            this.$message({
              type: "success",
              message: "已退出登录!",
            });
          }, 1000);
          // loginout()
          //   .then(res => {
          //     if (res.success) {
          //       //如果请求成功就让他2秒跳转路由
          //       setTimeout(() => {
          //         this.$store.commit('logout', 'false')
          //         this.$router.push({ path: '/login' })
          //         this.$message({
          //           type: 'success',
          //           message: '已退出登录!'
          //         })
          //       }, 1000)
          //     } else {
          //       this.$message.error(res.msg)
          //       this.logining = false
          //       return false
          //     }
          //   })
          //   .catch(err => {
          //     // 获取图形验证码
          //     this.getcode()
          //     this.logining = false
          //     this.$message.error('退出失败，请稍后再试！')
          //   })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 消息通知跳转-订单列表
    linkOrder() {
      this.$router.push("/pay/OrderList");
    },
    // 切换显示
    toggle(showtype) {
      this.collapsed = !showtype;
      this.$root.Bus.$emit("toggle", this.collapsed);
    },
  },
};
</script>
<style scoped>
/********************************************************************* 消息提示 ************************************************************/
/* 通知 */
.nactione{
  margin-top: 8px;
  margin-right: 20px;
}
.hearts {
  right: 3px;
  top: -3px;
  width: 6px;
  height: 6px;
  background: #fc5531;
  border-radius: 8px;
  color: #fff;
  position: absolute;
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
}
/deep/.el-menu-item.is-active {
  color: #757993 !important;
  background-color: #fff !important;
}
/deep/.el-menu-item {
  color: #8a8989 !important;
}
/deep/ .el-menu-item i {
  color: #8a8989;
}
.el-menu.el-menu--horizontal {
  background-color: #fff;
  height: 3.6rem;
  border-radius: 5px;
  overflow: hidden;
}
.notice {
  width: 89%;
  float: left;
  text-align: right;
  position: absolute;
}
.notice img {
  width: 1.35%;
  margin-top: 0.2rem;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
#head {
  overflow: hidden;
  display: flex;
  align-items: center;
  width: 13%;
  float: right;
  margin-top: 0.5rem;
  margin-right: 1%;
}
.headImg {
  display: inline-block;
  width: 20%;
  height: 20%;
  margin-left: 5%;
  /* vertical-align: middle; */
  /* margin-top: 0.2rem; */
}
.submenu {
  width: 100px;
  /* margin-top: 11px; */
  background-color: #fff;
}
/deep/ .el-submenu__title {
  margin-top: 0;
  font-size: 14px;
  color: #8a8989 !important;
}
.buttonimg {
  height: 60px;
  background-color: transparent;
  border: none;
}
.showimg {
  width: 26px;
  height: 26px;
  position: absolute;
  top: 17px;
  left: 17px;
}
.showimg:active {
  border: none;
}
#set {
  background-color: #fff;
  border: 1px solid #fff;
}
/deep/ .el-submenu__title:hover {
  background-color: #fff;
}
</style>